package util;

import java.util.*;

public class TreeNode {
    
    public int val;
    public TreeNode left;
    public TreeNode right;


    TreeNode() {}


    public TreeNode(int val) {
         this.val = val; 
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public String toString() {
        return "" + this.val;
    }
    public String printTree() {
        TreeNode cur = this;
        StringBuilder sb = new StringBuilder();
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(cur);
        sb.append("[");
        while (!queue.isEmpty()) {
            cur = queue.poll();
            sb.append(cur.val + ", ");
            if (cur.left != null) queue.offer(cur.left);
            if (cur.right != null) queue.offer (cur.right);
        }
        sb.delete(sb.length() - 2, sb.length());
        sb.append("]");
        return sb.toString();
    }

}
